/*
 * 退货申请单pdf controller
 */
public with sharing class ReturnOrderListPDFController {
	public String roId ;//退货申请单id
    public List<ReturnOrderListBean> rolList {get;set;}//tu退货明细
    public ReturnOrder__c ro {get;set;}//退货申请
    public Integer rows {get;set;}//行
    public String createdDate {get;set;}//申请日期


    public ReturnOrderListPDFController() {
    		roId = System.currentPageReference().getParameters().get('id');
    		rows = 0;
        	ro = [select Id,Account__r.Name ,CreatedBy.SubCompany__c,CreatedBy.Name ,CreatedDate ,ProcessingMethod__c
        		,InvoiceNumber__c ,Is_Return_Invoice__c from ReturnOrder__c where Id=:roId];
        		createdDate =Date.valueOf(ro.CreatedDate).format();
        	if (ro != null) {
        		rolList = new List<ReturnOrderListBean>();
        		Integer i = 1;
        			for ( ReturnOrderList__c rol: [select Id,Invname__c,SerialNo__c,Brand__c,Spec__c,RefundNumber__c,
        				BatchNumber__c,ExpirationDate__c,NCvpzwh__c from ReturnOrderList__c where ReturnOrderList__c =:ro.Id
        			]) {
        			
        			rolList.add(new ReturnOrderListBean(rol,i));
        			i++;
        			
        		}
        		
        		
        		if (rolList.size() < 8) {
        			for (Integer j = rolList.size()+1; j <= 8; j++) {
        				rolList.add(new ReturnOrderListBean(j));

        			}
        		}
        		

        		rows = rolList.size();

        	}
    }
    public class ReturnOrderListBean{
    	public Integer rownum {get;set;}//行号
        public String  invname {get;set;}//品名
        public String  serialno {get;set;}//货号
        public String  brand {get;set;}//生产厂家
        public String  spec {get;set;}//规格
        public Integer rnumber {get;set;}//数量
        public String  batchnumber {get;set;}//批号
        public String expiredate {get;set;}//失效期
        public String rigesterNo {get;set;}//注册证号/备案凭证号
      	public  Decimal rowheight {get;set;}

      	public ReturnOrderListBean(ReturnOrderList__c rol,Integer idx ){
      		rownum = idx;

      		invname = rol.Invname__c == null ? '':autoNextLine(rol.Invname__c,20);
      		//invname = autoNextLine('测试名称测试名称测试名称测试名称测试名称测试名称测试名称测试名称测试名称测试名称',20);
      		serialno = rol.SerialNo__c;
      		brand = rol.Brand__c;
      		spec = rol.Spec__c == null ? '':autoNextLine(rol.Spec__c,13);
      		//spec = autoNextLine('测试名称测试名称测试名称测试名称测试名称测试名称测试',13);

      		rnumber = rol.RefundNumber__c == null ? null :Integer.valueOf(rol.RefundNumber__c);
      		batchnumber = rol.BatchNumber__c;
      		expiredate = rol.ExpirationDate__c == null ?'': rol.ExpirationDate__c.format() ;
      		rigesterNo = rol.NCvpzwh__c == null ? '':autoNextLine(rol.NCvpzwh__c,16);
      		//rigesterNo = rol.NCvpzwh__c;
      		//rigesterNo = autoNextLine('测试名称测试名称测试名称测试名称测试名称测试名称测试名称测试名称',16);

      	}
      	public ReturnOrderListBean(Integer idx){
      		rownum  = idx ;
      	}

      	 private String autoNextLine(String s, Integer posLength ){
          if(s == null || s.length() <=posLength ) 
          {
              return s; 
          }
           String temp = '';
                  if(s.length() > posLength){
                     for(Integer i = 0; i < s.length(); i++){
                     if(Math.mod(i, posLength ) == 0){
                           if(s.length() > i + posLength){
                             temp += s.substring(i, i + posLength) + '\n'; 
                         }else{ 
                             temp+= s.substring(i,s.length());
                          } 
                  }
                     }
                  }

              return temp;
    	}
    }
}